CoinGecko
Hooks
useCoingeckoPrice
Given base token name and the supported currencies to get token price from CoinGecko.
Parameters
base: string
- the token name that you can get at URL while search in CoinGecko. Or find the token from https://api.coingecko.com/api/v3/coins/listquote: string
- (optional) the supported currencies in CoinGecko. Default quote isusd
. See https://api.coingecko.com/api/v3/simple/supported_vs_currencies
Returns
string | undefined
- token price
Example
App.tsx
import React from 'react'
import ReactDOM from 'react-dom'
import { useCoingeckoPrice } from '@usedapp/coingecko'
ReactDOM.render(<App />, document.getElementById('root'))
export function App() {
const etherPrice = useCoingeckoPrice('ethereum', 'usd')
return (
<div className="balance">
Ether price:
<p className="bold">{etherPrice} $</p>
</div>
)
}
useCoingeckoTokenPrice
Given token contract and the supported currencies to get token price from CoinGecko.
Parameters
contract: string
- the token contractquote: string
- (optional) the supported currencies in CoinGecko. Default quote isusd
. See https://api.coingecko.com/api/v3/simple/supported_vs_currenciesplatform: string
- (optional) the platform issuing tokens. Default platform id isethereum
. See https://api.coingecko.com/api/v3/asset_platforms
Returns
string | undefined
- token price
Example
App.tsx
import React from 'react'
import ReactDOM from 'react-dom'
import { useCoingeckoTokenPrice } from '@usedapp/coingecko'
ReactDOM.render(<App />, document.getElementById('root'))
export function App() {
const WETH_CONTRACT = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const wethPrice = useCoingeckoTokenPrice(WETH_CONTRACT, 'usd')
return (
<div className="balance">
Wrapped ether price:
<p className="bold">{wethPrice} $</p>
</div>
)
}